package com.able.concurrency.t5;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author abel.he
 * @data 2018/10/29 14:01
 * @describe
 * ThreadPollExecutor 自定义线程链接池
 */
public class Test8_ThreadPollExecutor {

    public static void main(String[] args) {
        // 模拟FixedThreadPoll， 核心线程5个，最大容量5个，线程的生命周期无线
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.SECONDS,
                new LinkedBlockingDeque<Runnable>());

        for (int i = 0; i < 6; i++) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        TimeUnit.MILLISECONDS.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + " Thread Execute");
                }
            });
        }

        System.out.println(executor);
        executor.shutdown();

        System.out.println(executor.isShutdown());
        System.out.println(executor.isTerminated());

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(executor);
        System.out.println(executor.isShutdown());
        System.out.println(executor.isTerminated());
    }
}
